package net.jxiny.oschina.synthetical.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;


import net.jxiny.oschina.LoginActivity;
import net.jxiny.oschina.R;
import net.jxiny.oschina.synthetical.Adapter.FollowAdapter;
import net.jxiny.oschina.synthetical.enyity.Follow;

import java.util.ArrayList;
import java.util.List;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

public class FollowFragment extends Fragment implements View.OnClickListener{

    private Unbinder binder;

    @BindView(R.id.recyclerView_follow)
    RecyclerView FollowView;

    private List<Follow> lists = new ArrayList<>();

    private FollowAdapter mFollowAdapter;
    private Button login;

    public FollowFragment() {

    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater,
                             @Nullable ViewGroup container,
                             @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragmengt_follow, container,
                false);
        binder = ButterKnife.bind(this, view);
        return view;
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        //TODO 假数据，后续修改为网络请求*******
        Follow follow = new Follow();
        for (int i = 0; i < 30; i++) {
            lists.add(follow);
        }

        //***********************************
        RecyclerView.LayoutManager manager = new LinearLayoutManager(getActivity(), RecyclerView.VERTICAL, false);

        FollowView.setLayoutManager(manager);
        mFollowAdapter = new FollowAdapter(R.layout.item_follow, lists);
        FollowView.setAdapter(mFollowAdapter);
        View view1 = LayoutInflater.from(getContext()).inflate(R.layout.header_focus, null);
        login=view1.findViewById(R.id.login);
        login.setOnClickListener(this);
        mFollowAdapter.setHeaderView(view1);
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        binder.unbind();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.login:
                Intent intent= new Intent(getActivity(), LoginActivity.class);
                startActivity(intent);
                break;
        }
    }
}
